package com.example.myapplication.ui.center

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.activity.addCallback
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.NavHostFragment
import com.example.myapplication.R
import com.xinnuo.analytics.android.ui.TrackFragment

class CenterFragment : TrackFragment() {

    private lateinit var centerViewModel: CenterViewModel

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        centerViewModel =
            ViewModelProvider(this).get(CenterViewModel::class.java)
        val root = inflater.inflate(R.layout.fragment_center, container, false)
        val textView: TextView = root.findViewById(R.id.text_center)
        centerViewModel.text.observe(viewLifecycleOwner, Observer {
            textView.text = it
        })

        textView.setOnClickListener {
            NavHostFragment.findNavController(this)
                .navigate(R.id.action_navigation_center_to_guideActivity)
        }

        requireActivity()
            .onBackPressedDispatcher
            .addCallback(this) {
                Log.i("=============", "CenterFragment")
            }

        return root
    }
}